package test4;

public class test {
    public static void main(String[] args)
    {
        System.out.println(add(1,2));
        System.out.println(add(1,2,3));
        System.out.println(add(1));
        System.out.println(add(1,5,6,1));
    }

    //可变个数形参
    public static int add(int ... args)
    {
        int sum = 0;
        for(int i : args)
        {
            sum += i;
        }
        return sum;
    }

}
